﻿using System;
using System.Collections.Generic;
using System.Text;
using YouHP.Utility;
using YouHP.BLL;
using System.Web;
using YouHP.Model;

namespace YouHP.Pages.User
{
    public class FriendList : YouHP.Pages.User.UserBasePage
    {

        protected override void ShowPage()
        {
            base.ShowPage();
            if (ErrorCount > 0) return;

            HandleCommon();
            if (ErrorCount > 0) return;

            if (IsPost) HandlePost();
            else HandleGet();
        }

        protected void HandlePost()
        {
            int fid = RequestTools.GetFormInt("fid", 0);
            int[] fidArray = new int[] { fid };
            bool succ = FriendBLL.Instance.DeleteFriend(UserData.Id, fidArray);
            if (succ)
            {

                this.Redirect("/User/FriendList.aspx");

            }
            else
            {
                this.AddErrLine("操作失败！");
                return;
            }

        }

        protected void HandleCommon()
        {
            this.SetTitle("病友");
            this.AddLocation("病友列表", "/User/FriendList.aspx");
        }


        protected List<UserInfo> FriendDataList = new List<UserInfo>();
        protected int PageIndex;
        protected int PageSize = 20;
        protected int DataCount;
        protected int PageCount;
        protected string PagingString;

        protected void HandleGet()
        {

            PageIndex = RequestTools.GetQueryInt("page", 1);

            FriendDataList = FriendBLL.Instance.GetFriendList(PageSize, PageIndex, UserData.Id, Constants.FriendPass, out DataCount);
            PageCount = Utils.GetPageCount(DataCount, PageSize);

            string query = HttpContext.Current.Request.Url.Query;
            query = Utils.RemoveQueryItem(query, "page");

            PagingString = this.GetPagingString(
                PageIndex,
                PageCount,
                "/User/FriendList.aspx" + query, "page");

        }


    }
}
